<html>
<head>
<title>管理系统</title>
<meta http-equiv=Content-Type content=text/html;charset=utf-8>
<#include "../inc/commonJs.html">
<script type="text/JavaScript">
var btnreload = {id : 'btnreload',text : '收消息',iconCls : 'icon-reload',handler : function() {	reloadEmail();}};
var btnadd = {id : 'btnadd',text : '发消息',iconCls : 'icon-add',handler : function() {addEmail();}};
var btneview = {id : 'btnedit',text : '查看消息',iconCls : 'icon-search',handler : function() {viewEmail2();}};
var btnedit = {id : 'btnedit',text : '编辑消息',iconCls : 'icon-edit',handler : function() {editEmail();}};
var btnredo = {id : 'btnedit',text : '恢复收件箱',iconCls : 'icon-redo',handler : function() {redoEmail();}};
var btnreply = {id : 'btnreply',text : '回复消息',iconCls : 'icon-edit',handler : function() {replyEmail();}};
var btndel = {id : 'btndel',text : '删除',iconCls : 'icon-cancel',handler : function() {delEmail();}};
var btninboxdel = {id : 'btndel',text : '删除',iconCls : 'icon-cancel',handler : function() {delInboxEmail();}};
var btndeleteddel = {id : 'btndel',text : '删除',iconCls : 'icon-cancel',handler : function() {delDeletedEmail();}};
var btnnet = {id : 'btnnet',text : '转发外网邮箱',iconCls : 'icon-print',handler : function() {sendRealEmail();}};
var btnnetset = {id : 'btnnetset',text : '设置外网邮箱',iconCls : 'icon-print',handler : function() {setEmail();}};
//工具栏var toolbar = [btnreload,btnadd,btnedit,btnreply,"-",btndel,"-",btnnet,btnnetset];
var toolbar1 = [btnreload,btneview,"-",btnadd,btnreply,btninboxdel,"-",btnnetset];//收件
var toolbar2 = [btneview,"-",btnadd,btnedit,btndel,"-",btnnet,btnnetset,"-"];//草稿
var toolbar3 = [btneview,"-",btnadd,btndel,"-",btnnet,btnnetset,"-"];//已发送
var toolbar4 = [btneview,"-",btnadd,btndeleteddel,btnredo,"-"];//已删除

var grid;
$(function() {
		//分类管理表格  
		grid = $('#emailgrid').datagrid({
        url:'listInEmail.do',  
        loadMsg:'数据加载中请稍后……',  
        pagination: true,  
        rownumbers: true, 
        striped: true,  
        singleSelect : true,  
        pageSize: [${syscfg.pageSize!10}],
        pageList: [${syscfg.pageList!10}],
        columns:[[  
             {field:'emailid',title: 'ID',align: 'center',width: '50'},  
             {field:'sender',title: '发件人',align: 'center',width: '100'},
             {field:'receiver',title: '收件人',align: 'center',width: '150'},
             {field:'cc',title: '转发外网',align: 'center',width: '200'},
             {field:'title',title: '标题',align: 'center',width: '300'},
             {field:'dt',title: '时间',align: 'center',width: '150'},
             {field:'isread',title: '状态',align: 'center',width: '80',
             	formatter: function(value,rowdata,index){
             		var str = '<a href="javascript:void(0)" onclick="chakan('+rowdata.emailid+')">阅读/回复</a>';
					if(value==0){
						str = '<a href="javascript:void(0)" onclick="chakan('+rowdata.emailid+')"><font color="red">未读</font></a>';
					}
					else if(value==1){
						str = '<a href="javascript:void(0)" onclick="chakan('+rowdata.emailid+')">已读</a>';
					}
					else if(value==2){
						str = '<a href="javascript:void(0)" onclick="chakan('+rowdata.emailid+')">已回复</a>';
					}
					return str;
				}
			}
        ]],
        toolbar : toolbar1,
		onDblClickCell: function(index,field,value){
			var emailid = $('#emailgrid').datagrid('getData').rows[index].emailid;
			viewEmail(emailid);
		}
      });
		/**/
		$('#emailtree').tree({
			url:'emailLeftTree.do',
		    lines:true,
		    animate:true,
		    onClick: function(node){
		    	var i = node.id;
		    	var _url = 'listInEmail.do';
		    	var tb = toolbar1;
		    	if(i == 1) {//收件箱
		    		//_url = 'listInEmail.do';
		    	} else if(i == 2) {//草稿箱
		    		tb = toolbar2;
		    		_url = 'listOutEmail.do';
		    	} else if(i == 3) {//已发送
		    		tb = toolbar3;
		    		_url = 'listOutEmail.do?zt=1';
		    	} else if(i == 4) {//已删除
		    		tb = toolbar4;
		    		_url = 'listInEmail.do?zt=1';
		    	}
		    	$('#emailgrid').datagrid({
		    		url : _url, toolbar: tb
		    	});
			}
		}); 
});
	//收消息
	function reloadEmail() {
		$('#emailgrid').datagrid({url:'listInEmail.do'}); 
	}
	//设置外网邮件
	function setEmail() {
		var url = '${request.contextPath}/xadmin/work/emailSet.do';
		top.modalwindow(url, grid,{width:450, height:250,title:'设置外网邮件'});
	}
	//发消息
	function addEmail() {
		var url = '${request.contextPath}/xadmin/work/emailWindow.do';
		var mwin = top.modalwindow(url, grid,{width:410, height:240,title:'发送内部消息',
		    buttons:[{
				text:'发送',
				iconCls:"icon-back",
				handler:function(){
					mwin.find('iframe')[0].contentWindow.sendEmail();
				}
				
			}, top.btn_save, top.btn_close]});
	}
	//
	function editEmail(emailid) {
		var selected = grid.datagrid('getSelected');
		if(!selected){
			top.noselectedalert();
			return;
		}
		var url = '${request.contextPath}/xadmin/work/emailWindow.do?emailid='+selected.emailid;
		var mwin = top.modalwindow(url, grid,{width:410, height:240,title:'编辑内部消息',
		    buttons:[{
				text:'发送',
				iconCls:"icon-back",
				handler:function(){
					mwin.find('iframe')[0].contentWindow.sendEmail();
				}
				
			}, top.btn_save, top.btn_close]});
	}
	//
	function viewEmail2() {
		var selected = grid.datagrid('getSelected');
		if(!selected){
			top.noselectedalert();
			return;
		}
		var url = '${request.contextPath}/xadmin/work/emailWindow.do?emailid='+selected.emailid;
		top.modalwindow(url, grid,{width:410,height:240,title:'查看内部消息',
		    buttons:[top.btn_close]   
		});
	}
	//
	function viewEmail(emailid) {
		var url = '${request.contextPath}/xadmin/work/emailWindow.do?emailid='+emailid;
		top.modalwindow(url, grid,{width:410,height:240,title:'查看内部消息',
		    buttons:[top.btn_close]   
		});
	}
	//
	function delEmail(){
		var selected = grid.datagrid('getSelected');
		if(!selected){
			top.noselectedalert();
			return;
		}
		$.messager.confirm('系统提示', '<br>&nbsp;&nbsp;&nbsp;&nbsp;你确定要删除该信息?', function(r) {
			if (r) {
				$.post("delEmail.do", { "emailid": selected.emailid},
				   function(data){
				   	grid.datagrid('reload'); 
				   	top.messagershow(data);
				});
			}
		});
	}
	//
	function delInboxEmail(){
		var selected = grid.datagrid('getSelected');
		if(!selected){
			top.noselectedalert();
			return;
		}
		$.messager.confirm('系统提示', '<br>&nbsp;&nbsp;&nbsp;&nbsp;你确定要删除该信息?', function(r) {
			if (r) {
				$.post("delInboxEmail.do", { "emailid": selected.emailid},
				   function(data){
				   	grid.datagrid('reload'); 
				   	top.messagershow(data);
				});
			}
		});
	}	
	//
	function delDeletedEmail(){
		var selected = grid.datagrid('getSelected');
		if(!selected){
			top.noselectedalert();
			return;
		}
		$.messager.confirm('系统提示', '<br>&nbsp;&nbsp;&nbsp;&nbsp;你确定要删除该信息?', function(r) {
			if (r) {
				$.post("delDeletedEmail.do", { "emailid": selected.emailid},
				   function(data){
				   	grid.datagrid('reload'); 
				   	top.messagershow(data);
				});
			}
		});
	}	
	//
	function redoEmail(){
		var selected = grid.datagrid('getSelected');
		if(!selected){
			top.noselectedalert();
			return;
		}
		$.messager.confirm('系统提示', '<br>&nbsp;&nbsp;&nbsp;&nbsp;你确定要恢复该信息?', function(r) {
			if (r) {
				$.post("redoEmail.do", { "emailid": selected.emailid},
				   function(data){
				   	grid.datagrid('reload'); 
				   	top.messagershow(data);
				});
			}
		});
	}	
	//回复消息
	function replyEmail() {
		var selected = grid.datagrid('getSelected');
		if(!selected){
			top.noselectedalert();
			return;
		}
		//
		var url = '${request.contextPath}/xadmin/work/emailReplyWindow.do?emailid='+selected.emailid;
		var modalwindow =  window.top.modalwindow(url, grid,{width:600, height:400, title:'回复邮件',
		    buttons:[{
				text:'回复',
				iconCls:"icon-back",
				handler:function(){
					modalwindow.find('iframe')[0].contentWindow.saveObj(selected.emailid);
				}
			},{
				text:'关闭',
				iconCls:"icon-cancel",
				handler:function(){
					grid.datagrid('reload'); 
					modalwindow.dialog('close');
				}
			}]   
		});
	}
	//发外部邮件
	function sendRealEmail() {
		var selected = grid.datagrid('getSelected');
		if(!selected){
			top.noselectedalert();
			return;
		}
		var url = '${request.contextPath}/xadmin/work/emailWindow.do?realEmail=1&&emailid='+selected.emailid;
		var mwin = top.modalwindow(url, grid,{ width:450,height:260, title:'发送外网邮件',
		    buttons:[{
				text:'发送',
				iconCls:"icon-back",
				handler:function(){
					mwin.find('iframe')[0].contentWindow.sendRealEmail();
				}
				
			}, top.btn_close]   
		});
	}
	//查看阅读状态
	function chakan(emailid){
		top.modalwindow('${request.contextPath}/xadmin/work/emailStateWindow.do?emailid='+emailid,'',{    
		    width:550, height:440, title:'邮件状态查看', buttons:[top.btn_close]   
		});
	}
</script>
</head>
<body class="easyui-layout">
<div data-options="region:'west',iconCls:'icon-mini-add',title:'我的消息', split:true" style="width:130px;">
	<div class="easyui-panel" data-options='fit:true,border:false'> 
		<ul id="emailtree" class="easyui-tree"></ul>
	</div>
</div>
<div data-options="region:'center'">
<table id="emailgrid" data-options="fit:true,border:false"></table>
</div>  
</body>
</html>